<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>会员兑换 - 记账助手</title>
    <link rel="stylesheet" href="styles.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <style>
        .redeem-header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 30px 20px;
            text-align: center;
            position: relative;
            overflow: hidden;
        }
        
        .redeem-header::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: float 6s ease-in-out infinite;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }
        
        .redeem-icon {
            font-size: 48px;
            margin-bottom: 15px;
            animation: bounce 2s infinite;
        }
        
        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
            40% { transform: translateY(-10px); }
            60% { transform: translateY(-5px); }
        }
        
        .redeem-title {
            font-size: 28px;
            font-weight: 700;
            margin-bottom: 8px;
            position: relative;
            z-index: 1;
        }
        
        .redeem-subtitle {
            font-size: 16px;
            opacity: 0.9;
            position: relative;
            z-index: 1;
        }
        
        .back-btn {
            position: absolute;
            top: 20px;
            left: 20px;
            background: rgba(255,255,255,0.2);
            border: none;
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            cursor: pointer;
            transition: all 0.3s ease;
            backdrop-filter: blur(10px);
            z-index: 2;
        }
        
        .back-btn:hover {
            background: rgba(255,255,255,0.3);
            transform: scale(1.1);
        }
        
        .redeem-container {
            padding: 30px 20px;
        }
        
        .redeem-form {
            background: white;
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.1);
            margin-bottom: 30px;
        }
        
        .form-title {
            font-size: 20px;
            font-weight: 700;
            color: #2d3748;
            margin-bottom: 20px;
            text-align: center;
        }
        
        .code-input-group {
            position: relative;
            margin-bottom: 25px;
        }
        
        .code-input {
            width: 100%;
            padding: 15px 20px;
            border: 2px solid #e2e8f0;
            border-radius: 15px;
            font-size: 16px;
            font-weight: 600;
            text-align: center;
            letter-spacing: 2px;
            text-transform: uppercase;
            transition: all 0.3s ease;
            background: #f8f9fa;
        }
        
        .code-input:focus {
            outline: none;
            border-color: #667eea;
            background: white;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        .code-input::placeholder {
            color: #a0aec0;
            font-weight: 400;
            letter-spacing: 1px;
        }
        
        .redeem-btn {
            width: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            color: white;
            padding: 15px;
            border-radius: 15px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        
        .redeem-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
        }
        
        .redeem-btn:disabled {
            background: #e2e8f0;
            color: #a0aec0;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        
        .redeem-btn .loading {
            display: none;
        }
        
        .redeem-btn.loading .loading {
            display: inline-block;
            animation: spin 1s linear infinite;
        }
        
        .redeem-btn.loading .text {
            display: none;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .tips-section {
            background: white;
            border-radius: 16px;
            padding: 20px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
            margin-bottom: 20px;
        }
        
        .tips-title {
            font-size: 16px;
            font-weight: 600;
            color: #2d3748;
            margin-bottom: 15px;
            display: flex;
            align-items: center;
        }
        
        .tips-title::before {
            content: '💡';
            margin-right: 8px;
        }
        
        .tips-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .tips-list li {
            color: #718096;
            font-size: 14px;
            line-height: 1.6;
            margin-bottom: 8px;
            padding-left: 20px;
            position: relative;
        }
        
        .tips-list li::before {
            content: '•';
            color: #667eea;
            font-weight: bold;
            position: absolute;
            left: 0;
        }
        
        .history-link {
            background: white;
            border-radius: 16px;
            padding: 20px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
            text-decoration: none;
            color: inherit;
            display: block;
            transition: all 0.3s ease;
        }
        
        .history-link:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 30px rgba(0,0,0,0.12);
            color: inherit;
            text-decoration: none;
        }
        
        .history-content {
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .history-info {
            display: flex;
            align-items: center;
        }
        
        .history-icon {
            width: 48px;
            height: 48px;
            border-radius: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 24px;
            margin-right: 15px;
            color: white;
        }
        
        .history-text {
            flex: 1;
        }
        
        .history-title {
            font-size: 16px;
            font-weight: 600;
            color: #2d3748;
            margin: 0 0 4px 0;
        }
        
        .history-desc {
            font-size: 14px;
            color: #718096;
            margin: 0;
        }
        
        .history-arrow {
            color: #a0aec0;
            font-size: 18px;
        }
        
        .success-animation {
            display: none;
            text-align: center;
            padding: 40px 20px;
        }
        
        .success-icon {
            font-size: 64px;
            margin-bottom: 20px;
            animation: successBounce 0.6s ease-out;
        }
        
        @keyframes successBounce {
            0% { transform: scale(0); }
            50% { transform: scale(1.2); }
            100% { transform: scale(1); }
        }
        
        .success-title {
            font-size: 24px;
            font-weight: 700;
            color: #48bb78;
            margin-bottom: 10px;
        }
        
        .success-desc {
            color: #718096;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="screen">
        <div class="app-container">
            <div class="redeem-header">
                <button class="back-btn" onclick="history.back()">
                    ←
                </button>
                <div class="redeem-icon">🎫</div>
                <div class="redeem-title">会员兑换</div>
                <div class="redeem-subtitle">输入兑换码，立即升级会员</div>
            </div>
            
            <div class="redeem-container">
                <div class="redeem-form" id="redeemForm">
                    <div class="form-title">输入兑换码</div>
                    <div class="code-input-group">
                        <input type="text" class="code-input" id="redeemCode" placeholder="请输入兑换码" maxlength="16">
                    </div>
                    <button class="redeem-btn" id="redeemBtn" onclick="processRedeem()">
                        <span class="loading">⟳</span>
                        <span class="text">立即兑换</span>
                    </button>
                </div>
                
                <div class="success-animation" id="successAnimation">
                    <div class="success-icon">🎉</div>
                    <div class="success-title">兑换成功！</div>
                    <div class="success-desc">恭喜您成功升级为会员，享受专属特权</div>
                </div>
                
                <div class="tips-section">
                    <div class="tips-title">兑换说明</div>
                    <ul class="tips-list">
                        <li>兑换码由16位字母和数字组成，不区分大小写</li>
                        <li>每个兑换码只能使用一次，兑换后立即生效</li>
                        <li>兑换码有效期请以实际获得的兑换码为准</li>
                        <li>如遇兑换问题，请联系客服获得帮助</li>
                    </ul>
                </div>
                
                <a href="member-redeem-history.html" class="history-link">
                    <div class="history-content">
                        <div class="history-info">
                            <div class="history-icon">📋</div>
                            <div class="history-text">
                                <div class="history-title">兑换记录</div>
                                <div class="history-desc">查看历史兑换记录</div>
                            </div>
                        </div>
                        <div class="history-arrow">›</div>
                    </div>
                </a>
            </div>
        </div>
    </div>
    
    <script>
        // 兑换码输入格式化
        $('#redeemCode').on('input', function() {
            let value = $(this).val().toUpperCase().replace(/[^A-Z0-9]/g, '');
            if (value.length > 16) {
                value = value.substring(0, 16);
            }
            $(this).val(value);
            
            // 启用/禁用兑换按钮
            if (value.length >= 8) {
                $('#redeemBtn').prop('disabled', false);
            } else {
                $('#redeemBtn').prop('disabled', true);
            }
        });
        
        // 处理兑换
        function processRedeem() {
            const code = $('#redeemCode').val().trim();
            const btn = $('#redeemBtn');
            
            if (code.length < 8) {
                showToast('请输入有效的兑换码', 'error');
                return;
            }
            
            // 显示加载状态
            btn.addClass('loading').prop('disabled', true);
            
            // 模拟兑换请求
            setTimeout(() => {
                // 模拟兑换结果
                const isSuccess = Math.random() > 0.3; // 70% 成功率
                
                btn.removeClass('loading');
                
                if (isSuccess) {
                    // 兑换成功
                    $('#redeemForm').fadeOut(300, function() {
                        $('#successAnimation').fadeIn(300);
                    });
                    
                    // 保存兑换记录
                    saveRedeemRecord(code, '年度会员', '2024-12-31');
                    
                    // 3秒后跳转到会员权益页面
                    setTimeout(() => {
                        location.href = 'member-benefits.html';
                    }, 3000);
                } else {
                    // 兑换失败
                    btn.prop('disabled', false);
                    const errorMessages = [
                        '兑换码无效，请检查后重试',
                        '兑换码已过期',
                        '兑换码已被使用',
                        '网络错误，请稍后重试'
                    ];
                    const randomError = errorMessages[Math.floor(Math.random() * errorMessages.length)];
                    showToast(randomError, 'error');
                }
            }, 2000);
        }
        
        // 保存兑换记录到本地存储
        function saveRedeemRecord(code, memberType, expireDate) {
            let records = JSON.parse(localStorage.getItem('redeemRecords') || '[]');
            const newRecord = {
                id: Date.now(),
                code: code,
                memberType: memberType,
                redeemDate: new Date().toISOString().split('T')[0],
                expireDate: expireDate,
                status: 'success'
            };
            records.unshift(newRecord);
            localStorage.setItem('redeemRecords', JSON.stringify(records));
        }
        
        // 显示提示消息
        function showToast(message, type = 'info') {
            // 创建提示元素
            const toast = $(`
                <div class="toast-message" style="
                    position: fixed;
                    top: 50%;
                    left: 50%;
                    transform: translate(-50%, -50%);
                    background: ${type === 'error' ? '#fed7d7' : '#c6f6d5'};
                    color: ${type === 'error' ? '#c53030' : '#2f855a'};
                    padding: 15px 20px;
                    border-radius: 10px;
                    font-weight: 600;
                    z-index: 9999;
                    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
                ">${message}</div>
            `);
            
            $('body').append(toast);
            
            // 3秒后自动消失
            setTimeout(() => {
                toast.fadeOut(300, function() {
                    $(this).remove();
                });
            }, 3000);
        }
        
        // 页面加载动画
        $(document).ready(function() {
            $('.redeem-form, .tips-section, .history-link').each(function(index) {
                $(this).css({
                    'opacity': '0',
                    'transform': 'translateY(20px)'
                }).delay(index * 100).animate({
                    'opacity': '1'
                }, 500).css('transform', 'translateY(0)');
            });
        });
    </script>
</body>
</html>